 /**********************************************************
 *
 *  PRELIMINARIES.ADO: SET PRELIMINARIES FOR DO FILES
 * 
 * Inputs: 1) Standard inputs to stata file:
 *				a) maxvar (default 5000)
 *				b) matsize (default 5000)
 *				c) sortseed
 *				d) seed 
 *				e) linesize (default 255)
 *				f) loadglob (space-delimited list of global variable files)
 * 
 * Output: 1) Message about any errors printed to the log
 * 
 **********************************************************/ 
version 12

program define preliminaries
 
 quietly{
	
	syntax , [matsize(string) maxvar(string) sortseed(string) linesize(string) loadglob(string) seed(string) aoutf(string) doutf(string)]  

	if "`sortseed'"==""{
		local sortseed 47
	}	
	if "`matsize'"==""{
		local matsize 5000
	}	
	if "`linesize'"==""{
		local linesize 255
	}
	if "`maxvar'"==""{
		local maxvar 5000
	}
	if "`seed'"==""{
		local seed 147
	}
	
	clear all
	
	set matsize `matsize'
	set linesize `linesize'
	set maxvar `maxvar'
	set sortseed `sortseed'
	set seed `seed'

	*Output Files
	if "`doutf'"!= "" {
		cap mkdir "`doutf'"
		local files : dir "`doutf'" files "*.dta"
		foreach f in `files' {
			cap erase "`doutf'/`f'"
		}
		local list1 : dir "`doutf'" files "*.png"
		local list2 : dir "`doutf'" files "*.txt"
		local list3 : dir "`doutf'" files "*.xls"
		local list4 : dir "`doutf'" files "*.eps"
		local list5 : dir "`doutf'" files "*.log"
		foreach f in `list1' {
			cap erase "`doutf'/`f'"
		}
		foreach f in `list2' {
			cap erase "`doutf'/`f'"
		}
		foreach f in `list3' {
			cap erase "`doutf'/`f'"
		}
		foreach f in `list4' {
			cap erase "`doutf'/`f'"
		}	
		foreach f in `list5' {
			cap erase "`doutf'/`f'"
		}		
	}
	
}

end
